// BalanceInquiry.java
// Represents a balance inquiry ATM transaction
import java.text.*;

//subclass BalanceInquiry starts
public class BalanceInquiry extends Transaction {
	// BalanceInquiry constructor
	public BalanceInquiry(int userClientNumber, int userAccountNumber,
			Screen atmScreen, BankDatabase atmBankDatabase) {
		super(userClientNumber, userAccountNumber, atmScreen, atmBankDatabase);
	} // end BalanceInquiry constructor
	
	DecimalFormat df = new DecimalFormat("##.00");
	
	// performs the transaction
	@Override 
	// Overrides the superclass method: abstract public void execute();
	public void execute() {
		// get references to bank database and screen
		BankDatabase bankDatabase = getBankDatabase();
		Screen screen = getScreen();

		// get the years from account involved
		int years = bankDatabase.getAccount(getAccountNumber()).getYears();

		// loops through accounts looking for account type and updates
		// interestRate accordingly
		for (int i = 0; i < BankDatabase.customerList.size(); i++) {
			for (int j = 0; j < BankDatabase.customerList.get(i)
					.getAccountList().size(); j++) {
				if (BankDatabase.customerList.get(i).getAccountList().get(j)
						.getAccountType().equals("Overdraft"))
					BankDatabase.customerList.get(i).getAccountList().get(j)
							.updateInterestRate(years);
			} // end for loop
		} // end for loop
		{ // loops through accounts looking for account type and updates
			// interestRate accordingly
			for (int i = 0; i < BankDatabase.customerList.size(); i++) {
				for (int j = 0; j < BankDatabase.customerList.get(i)
						.getAccountList().size(); j++) {
					if (BankDatabase.customerList.get(i).getAccountList()
							.get(j).getAccountType().equals("Savings"))
						BankDatabase.customerList.get(i).getAccountList()
								.get(j).updateInterestRate(years);
				} // end for loop
			} // end for loop
			{ // loops through accounts looking for account type and updates
				// interestRate accordingly
				for (int i = 0; i < BankDatabase.customerList.size(); i++) {
					for (int j = 0; j < BankDatabase.customerList.get(i)
							.getAccountList().size(); j++) {
						if (BankDatabase.customerList.get(i).getAccountList()
								.get(j).getAccountType().equals("Budget"))
							BankDatabase.customerList.get(i).getAccountList()
									.get(j).updateInterestRate(years);
					}// end for loop
				} // end for loop

				// get the available balance for the account involved
				double availableBalance = bankDatabase
						.getAvailableBalance(getAccountNumber());

				// get the total balance for the account involved
				double totalBalance = bankDatabase
						.getTotalBalance(getAccountNumber());

				// get the interestBalance for the account involved
				double interestBalance = bankDatabase
						.getInterestBalance(getAccountNumber());

				// display the balance information on the screen
				// formats the output with df.format to display only 2 decimals 
				screen.printTop();
				screen.printMessage("Balance Information:");
				screen.printBlank();
				screen.printMessage("- Available balance:              $"
						+ df.format(availableBalance));
				screen.printMessage(" - Total balance:                  $"
						+ df.format(totalBalance));
				screen.printMessage(" - Balance with 3 years interest:  $"
						+ df.format(interestBalance));
				screen.printBot();
				screen.displayMessageLine("");
			} // end for loop 1
		} // end for loop 2
	} // end method execute
} // end class BalanceInquiry
/**************************************************************************
 * (C) Copyright 1992-2012 by Deitel & Associates, Inc. and * Pearson Education,
 * Inc. All Rights Reserved. * * DISCLAIMER: The authors and publisher of this
 * book have used their * best efforts in preparing the book. These efforts
 * include the * development, research, and testing of the theories and programs
 * * to determine their effectiveness. The authors and publisher make * no
 * warranty of any kind, expressed or implied, with regard to these * programs
 * or to the documentation contained in these books. The authors * and publisher
 * shall not be liable in any event for incidental or * consequential damages in
 * connection with, or arising out of, the * furnishing, performance, or use of
 * these programs. *
 *************************************************************************/
